<?php
class BZ_Config extends CI_Config
{
    public $main_base_url       = 'http://www.zxkj918.com/';
    public $images_url          = 'http://img.zxkj918.com/';
    public $login_url           = 'http://login.zxkj918.com/';
    public $gongying_url        = 'http://gongying.zxkj918.com/';
    public $wap_base_url        = 'http://wap.zxkj918.com/';

    /**
     * 构造函数初始化https解决
     */
    public function __construct()
    {
        $this->config =& get_config();
        $httpType  = 'http';
        if ($this->config['base_url'] == '') {
            if (isset($_SERVER['HTTP_HOST'])) {
                $base_url  = $httpType.'://'. $_SERVER['HTTP_HOST'];
                $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
            } else {
                $base_url = $httpType.'://localhost/';
            }
            $this->set_item('base_url', $base_url);
        }
        //配置域名
        $this->main_base_url = $httpType.'://www'.strstr($_SERVER['HTTP_HOST'], '.').'/';
        $this->login_url     = $httpType.'://login'.strstr($_SERVER['HTTP_HOST'], '.').'/';
        $this->gongying_url  = $httpType.'://gongying'.strstr($_SERVER['HTTP_HOST'], '.').'/';
        $this->wap_base_url  = $httpType.'://wap'.strstr($_SERVER['HTTP_HOST'], '.').'/';
    }

    /**
     * 图片上传路径
     * @param string $dirname
     * @param string $imageName
     * @return string
     */
    public function upload_image_path($imageName = '', $dirname = 'uploads')
    {
        if (!empty($imageName)) {
            return FCPATH.'/'.$dirname.'/'.$imageName;
        }
        return FCPATH.'/'.$dirname.'/';
    }

    /**
     * 线路图片显示路径
     * @param string $dirname
     * @param string $imageName
     * @param bool $default
     * @return string
     */
    public function show_image_url($imageName = '', $dirname = 'uploads', $default = false)
    {
        if (empty($imageName)) {
            return $default == false ? '/skins/admin/images/nophoto.jpg' : $imageName;
        }
        if (strpos($imageName, 'http') === false) {
            $src = $this->images_url.$dirname.$imageName;
        } else {
            $src = $imageName;
        }
        return $src;
    }
}